<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../src/css/reset.css" />
		<link rel="stylesheet" type="text/css" href="../../src/css/main.css" />
		<link rel="stylesheet" type="text/css" href="../../libs/leaflet/leaflet.css" />
		<script src="../../libs/leaflet/leaflet.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../libs/leaflet/leaflet.ChineseTmsProviders.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="map"></div>
		<div >
			<button type="button" onclick="setBaseLayer('TianDiTu')">天地图</button>
			<button type="button" onclick="setBaseLayer('GaoDe')">高德</button>
			<button type="button" onclick="setBaseLayer('Google')">谷歌</button>
		</div>
		<script type="text/javascript"  id="my_script">
			var  flag = 'TianDiTu' // 显示那个类型的地图
			let map = L.map('map', {
				center: [32.444721222054795, 119.4224873962402], // leaflet 所有坐标都是纬度在前,经度在后的
				zoom: 16
			})
			let TianDiTu_map = L.tileLayer.chinaProvider('TianDiTu.Normal.Map', {
				maxZoom: 18,
				minZoom: 10
			})
			let TianDiTu_annotion = L.tileLayer.chinaProvider('TianDiTu.Normal.Annotion', {
				maxZoom: 18,
				minZoom: 10
			})
			let GaoDe_map = L.tileLayer.chinaProvider('GaoDe.Normal.Map', {
				maxZoom: 18,
				minZoom: 10
			})
			let Google_map = L.tileLayer.chinaProvider('Google.Normal.Map', {
				maxZoom: 18,
				minZoom: 10
			})
			
			setBaseLayer(flag)
			
			function setBaseLayer(flag){
				if(map.hasLayer(TianDiTu_map)){
					TianDiTu_map.remove()
					TianDiTu_annotion.remove()
				}
				if(map.hasLayer(GaoDe_map)){
					GaoDe_map.remove()
				}
				if(map.hasLayer(Google_map)){
					Google_map.remove()
				}
				
				if(flag === 'TianDiTu'){
					map.addLayer(TianDiTu_map)
					map.addLayer(TianDiTu_annotion)
				} else if (flag === 'Google'){
					map.addLayer(Google_map)
				} else{
					// 上面这段代码不加看起来也是一样的,因为是先添加的天地图地图,然后 添加高德地图,高德地图会盖在上面,天地图就看不到了 ...反之,也能成立
					map.addLayer(GaoDe_map)
				}
			}
		</script>
	</body>
</html>
